package com.dfbz.controller.meet;

import com.dfbz.controller.BaseServlet;
import com.dfbz.model.Meeting;
import com.dfbz.service.impl.MeetingServletImp;
import com.dfbz.utils.PagingUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@WebServlet("/meet/*")
public class MeetController extends BaseServlet {

    private MeetingServletImp meetingServletImp=new MeetingServletImp();

    public void meetProcess(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String meetPage = req.getParameter("meetPage");
        String meetTitle = req.getParameter("MeetTitle");
        if (null==meetTitle){
            meetTitle="";
        }
        Integer currPage;
        if (meetPage==null){
            currPage=1;
        }else {
            int i = Integer.parseInt(meetPage);
            currPage=i;
        }
        Integer allMeetingNum = meetingServletImp.getAllMeetingNum(meetTitle);
        PagingUtil pagingUtil = new PagingUtil();
        pagingUtil.setCurrPage(currPage);
        pagingUtil.setTotalCount(allMeetingNum);
        Integer pageSize = pagingUtil.getPageSize();
        int i = (currPage - 1) * pageSize;
        List<Meeting> allMeeting = meetingServletImp.getAllMeeting(meetTitle, i, pageSize);
        pagingUtil.setData(allMeeting);
        System.out.println(allMeeting.toString());
        req.setAttribute("meetingMessage",pagingUtil);
        req.getRequestDispatcher("/html/meeting.jsp").forward(req,resp);
    }

    public void MeetingDetails(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int meetingId = Integer.parseInt(req.getParameter("meetingId"));
        Meeting byId = meetingServletImp.getById(meetingId);
        req.setAttribute("byIdMeeting",byId);
        req.getRequestDispatcher("/html/meeting_detail.jsp").forward(req,resp);
    }


}
